package shun.demo.remote.display.client;

import android.animation.ObjectAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.LinearInterpolator;
import shun.demo.R;
import shun.demo.remote.display.model.Property;

/**
 * Created by chen on 14-5-9.
 */
public class XScreenActivity extends Activity implements View.OnClickListener {

    private XScreen mXScreen;
    private View mXScreenView;
    private View mXImage;
    private ObjectAnimator mAnimator;

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, XScreenActivity.class);
        activity.startActivity(intent);
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xscreen);
        mXScreenView = findViewById(R.id.xscreen);
        mXScreen = XScreen.get();
        mXScreenView.scrollTo(mXScreen.getScreenLeft(), 0);
        mXImage = findViewById(R.id.ximage);
        XScreenHandler.get().setTarget(mXImage);
        mAnimator = ObjectAnimator.ofFloat(mXImage, "x", 0.0f, 1500.0f);
        mAnimator.setDuration(5000);
        mAnimator.setInterpolator(new LinearInterpolator());
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public void onClick(View v) {
        if (mAnimator.isRunning()) {
            mAnimator.cancel();
        }
        mAnimator.start();
        Property property = new Property(mXImage.getX());
        mXScreen.send(property);
    }
}